package com.isis.jdo.crud;

import java.util.List;

import javax.jdo.Extent;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import com.isis.jdo.entity.UserConnexion;
import com.isis.jdo.PMF;

public class ManagerDataStore {
	
	public void addUserConnexion(String email){
	
		PersistenceManager pm = PMF.getPersistenceManager();
		UserConnexion userConnexion=new UserConnexion(email);	
		
		try {
			pm.makePersistent(userConnexion);
			
		}
		finally {
	       
	        pm.close();
	    }
	}
	public int countUserConnexion(String email){
		int rep=0;
		PersistenceManager pm = PMF.getPersistenceManager();
		
		Query query = pm.newQuery("select from com.isis.jdo.entity.UserConnexion " +
                 "where email == emailParam " +
                 "parameters String emailParam ");
		try {
			
			List<UserConnexion> results = (List<UserConnexion>) query.execute(email);
			if (!results.isEmpty()) {
	            
	            	rep=results.size();
	            
	        } else {
	        	rep=0;
	        }
		}
		finally {
	        query.closeAll();
	        pm.close();
	    }
		
		return rep;
	}
	public void deleteConnexion (long key){
		PersistenceManager pm = PMF.getPersistenceManager();
		UserConnexion userConnexion = pm.getObjectById(UserConnexion.class, key);
		pm.deletePersistent(userConnexion);
		pm.close();
	}
	


}
